package com.example.NeteaseCloudMusicApi.ui.activity;
//NeteaseCloudMusicApiLearningProject

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.example.NeteaseCloudMusicApi.entity.LoginDTO;
import com.example.NeteaseCloudMusicApi.R;
import com.example.NeteaseCloudMusicApi.ui.fragment.FoundFragment;
import com.example.NeteaseCloudMusicApi.ui.fragment.KtvFragment;
import com.example.NeteaseCloudMusicApi.ui.fragment.MyFragment;
import com.example.NeteaseCloudMusicApi.ui.fragment.PlayerFragment;
import com.mxn.soul.flowingdrawer_core.FlowingDrawer;
import com.mxn.soul.flowingdrawer_core.FlowingMenuLayout;
import com.next.easynavigation.view.EasyNavigationBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class MainActivity extends AppCompatActivity {
//    CircleImageView mHeader;
//    TextView mUsername;
    private FlowingMenuLayout flowingDrawer;
    private EasyNavigationBar easyNavigationBar;

    private String[] tabText = {"发现", "播客", "我的", "K歌", "云村"};
    //未选中icon
    private int[] normalIcon = {R.drawable.found, R.drawable.podcast, R.drawable.my, R.drawable.k_song, R.drawable.cloud_village};
    //选中时icon
    private int[] selectIcon = {R.drawable.found1, R.drawable.podcast1, R.drawable.my1, R.drawable.k_song1, R.drawable.cloud_village1};
    private List<Fragment> fragmentList = new ArrayList<>();

    @BindView(R.id.iv_main_header)
    CircleImageView mHeader;

    @BindView(R.id.tv_main_username)
    TextView mUsername;

    @OnClick(R.id.ll_main_login)
    void login() {
        Intent intent = new Intent();
        intent.setClass(this, LoginActivity.class);
        startActivityForResult(intent, 999);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //绑定初始化ButterKnife
        ButterKnife.bind(this);

        easyNavigationBar = findViewById(R.id.navigationBar);
        flowingDrawer = findViewById(R.id.menuLayout);

//        mHeader = findViewById(R.id.iv_main_header);
//        mUsername = findViewById(R.id.tv_main_username);

        flowingDrawer.setFitsSystemWindows(true);//将侧边栏顶部延伸至status bar
        flowingDrawer.setClipToPadding(false); //将主页面顶部延伸至status bar;虽默认为false,但经测试,DrawerLayout需显示设置
        initView();
    }

    /*
    主界面视图-底部导航栏
     */
    public void initView(){

        fragmentList.add(new FoundFragment());
        fragmentList.add(new PlayerFragment());
        fragmentList.add(new MyFragment());
        fragmentList.add(new KtvFragment());
        fragmentList.add(new MyFragment());

        easyNavigationBar.titleItems(tabText)//Tab文字集合
                .fragmentList(fragmentList)//存放fragment的集合
                .fragmentManager(getSupportFragmentManager())//fragment管理器
                .normalIconItems(normalIcon)   //Tab未选中图标集合
                .selectIconItems(selectIcon)   //Tab选中图标集合
                .fragmentManager(getSupportFragmentManager())
                .iconSize(40)     //Tab图标大小
                .tabTextSize(10)   //Tab文字大小
                .tabTextTop(2)     //Tab文字距Tab图标的距离
                .normalTextColor(Color.parseColor("#666666"))   //Tab未选中时字体颜色
                .selectTextColor(Color.parseColor("#333333"))   //Tab选中时字体颜色
                .scaleType(ImageView.ScaleType.CENTER_INSIDE)  //同 ImageView的ScaleType
                .navigationBackground(Color.parseColor("#ffffff"))   //导航栏背景色
                .setOnTabClickListener(new EasyNavigationBar.OnTabClickListener() {
                    @Override
                    public boolean onTabSelectEvent(View view, int position) {
                        //Tab点击事件  return true 页面不会切换

                        return false;
                    }

                    @Override
                    public boolean onTabReSelectEvent(View view, int position) {
                        //Tab重复点击事件
                        return false;
                    }
                })
                .smoothScroll(false)  //点击Tab  Viewpager切换是否有动画
                .canScroll(true)    //Viewpager能否左右滑动
                .navigationHeight(70)  //导航栏高度
//                .lineHeight(100)         //分割线高度  默认1px
                .lineColor(Color.parseColor("#ffffff"))
                .hasPadding(true)    //true ViewPager布局在导航栏之上 false有重叠
//                .hintPointLeft(-3)  //调节提示红点的位置hintPointLeft hintPointTop（看文档说明）
//                .hintPointTop(-3)
//                .hintPointSize(6)    //提示红点的大小
//                .msgPointLeft(-10)  //调节数字消息的位置msgPointLeft msgPointTop（看文档说明）
//                .msgPointTop(-10)
//                .msgPointTextSize(9)  //数字消息中字体大小
//                .msgPointSize(18)    //数字消息红色背景的大小
                .textSizeType(EasyNavigationBar.TextSizeType.TYPE_DP)  //字体单位
                // 建议使用DP  可切换SP
                //.setupWithViewPager() ViewPager或ViewPager2
                .build();

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 999 && resultCode == 999) {
            LoginDTO loginDTO = (LoginDTO) data.getSerializableExtra("result");
            Glide.with(this).load(loginDTO.getProfile().getAvatarUrl()).into(mHeader);
            mUsername.setText(loginDTO.getProfile().getNickname());
        }
    }

}